package com.twu.biblioteca;

public class Book implements LibraryItem {
    private final String code;
    private final String title;
    private final String author;

    public Book(String code, String title, String author) {
        this.code = code;
        this.title = title;
        this.author = author;
    }

    @Override
    public String toString() {
        return String.format("%s. %s. By %s", code, title, author);
    }

    public String getCode() {
        return code;
    }

    @Override
    public boolean equals(Object other) {
        return other instanceof Book && this.toString().equals(other.toString());
    }

    @Override
    public int hashCode() {
        int result = code.hashCode();
        result = 31 * result + title.hashCode();
        result = 31 * result + (author != null ? author.hashCode() : 0);
        return result;
    }
}